#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int N=1e6+5;

bool cmp(pair<int,int> a,pair<int,int> b){
    if(a.second!=b.second)return a.second<b.second;
    else return a.first<b.first;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>>n;
    vector<pair<int,int>> pr(n);
    for(int i=0;i<n;i++)cin>>pr[i].first>>pr[i].second;
    sort(pr.begin(),pr.end(),cmp);
    ll ans=0;
    for(int i=1;i<n;i++){
        int l=0,r=i-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(pr[i].first<=pr[mid].second){
                r=mid-1;
            }else{
                l=mid+1;
            }
        }
        ans+=i-1-l+1;
    }
    cout<<ans;

    return 0;
}